package com.base.commonlib.utils;



import com.base.commonlib.base.BaseApp;
import com.base.commonlib.bean.DaoSession;
import com.base.commonlib.bean.RoadEntity;
import com.base.commonlib.bean.RoadEntityDao;
import com.base.commonlib.bean.UserRoad;
import com.base.commonlib.bean.UserRoadDao;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by arvin on 2018/10/29.
 */

public class MineRoadUtil {

    public static List<RoadEntity> getMineRoads(String userId) {
        ArrayList<RoadEntity> mineRoads = new ArrayList<>();
        DaoSession daoSession = BaseApp.getDaoSession();
        UserRoadDao userRoadDao = daoSession.getUserRoadDao();
        QueryBuilder<UserRoad> userRoadQueryBuilder = userRoadDao.queryBuilder();
        List<UserRoad> userRoads = userRoadQueryBuilder.where(UserRoadDao.Properties.UserId.eq(userId)).list();
        RoadEntityDao roadEntityDao = daoSession.getRoadEntityDao();
        for (UserRoad item : userRoads) {
            try {

                QueryBuilder<RoadEntity> roadEntityQueryBuilder = roadEntityDao.queryBuilder();
                RoadEntity unique = roadEntityQueryBuilder.where(RoadEntityDao.Properties.RoadNo.eq(item.getRoadNo())).unique();
                if (unique != null) {
                    mineRoads.add(unique);
                }
            } catch (Exception e) {

            }


        }
        return mineRoads;
    }

    public static List<RoadEntity> getRoads() {
        DaoSession daoSession = BaseApp.getDaoSession();
        RoadEntityDao roadEntityDao = daoSession.getRoadEntityDao();
        return roadEntityDao.loadAll();
    }
}
